Kwikfit IPP imports
Introduction
Kwikfit generates invoice files from their IPP system containing completed job lines. These JSON files are imported into ViSN to automatically create invoices and mark enquiries as completed, eliminating the need for manual invoice entry.
Purpose
To streamline the invoicing process, Kwikfit exports invoice data from their IPP system in a JSON format. This file is imported into ViSN, where the system automatically:
- Validates the invoice data against existing enquiries
- Matches invoices to enquiries by VRM and enquiry number
- Verifies invoice totals match ViSN calculations
- Progresses enquiries to "Completed" status
- Creates invoices in ViSN with the IPP invoice details
File format
JSON format - *.json
The JSON file must contain an array of objects, where each object has an INVOICE_HEADER property with the following structure:
Fields
| Column | Field | Type | Length | Comment | Mandatory | Example |
|---|---|---|---|---|---|---|
| A | ACCOUNT_NO | Text | 100 | Kwikfit account number for the lease company. This must match the account mapping in ViSN. | Yes | M5909U |
| B | INVOICE_NO | Text | 100 | Invoice number from IPP system. This will be saved as the invoice number in ViSN. | Yes | YE374831 |
| C | TAX_DATE | Date | 10 | DD/MM/YYYY - Tax point date for the invoice. This will be used as the tax point date in ViSN. | Yes | 24/11/2025 |
| D | DEPOT_NO | Text | 100 | Kwikfit depot/supplier ID. This must match a service unit's supplierId in ViSN. | Yes | 669 |
| E | CAR_REGISTRATION | Text | 100 | Vehicle Registration Mark (VRM). Must match the VRM on the enquiry in ViSN. Validated against VRM regex pattern. | Yes | SN74USH |
| F | INVOICE_VALUE | Number(9,2) | 12 | Total invoice value (net + VAT). Must match the calculated total in ViSN. Format: nnnnnn.nn | Yes | 245.71 |
| G | VAT_TOTAL | Number(9,2) | 12 | Total VAT amount. Format: nnnnnn.nn | Yes | 43.27 |
| H | ORDER_NO | Text | 100 | Enquiry number in ViSN. Must be numeric and match an existing enquiry number. | Yes | 57294658 |
High level flow
- Process
- Sequence
- Flow
Import process
Overview
The sequence diagram below illustrates the processing flow for the given invoice IPP records.
File upload and processing
- File Location: The import file must be uploaded to Google Cloud Storage in the designated import drop path.
- Import Trigger: Cloud Scheduler provides the account ID and file location to the import manager service. The import is triggered via a request with the following payload:
bucket→ Google Cloud Storage bucket nameimportFileDropPath→ Path where the file is located in the bucketimportFileName→ Name of the JSON file to importappDirectory→ Local directory path for temporary file storageaccountId→ Supplier group account ID in ViSNpersist→ Boolean flag to determine if invoices should be created (true) or only validated (false)fatalErrorEmailToAddress→ Email address to receive fatal error notifications
Example payload:
{
"bucket": "import-bucket-name",
"importFileDropPath": "kwikfit-ipp/",
"importFileName": "kwikfit_invoices_20250115.json",
"appDirectory": "/tmp/imports/",
"accountId": "RMZj6hYyP4PqhobUm1zw",
"persist": true,
"fatalErrorEmailToAddress": "admin@example.com"
}
Data validation
-
JSON Parsing: The file is parsed as JSON, extracting objects with
INVOICE_HEADERproperties. -
Schema Validation: Each invoice header object is validated against the
kwikfitIppInvoiceSchema:- All mandatory fields must be present and non-empty
TAX_DATEmust be in DD/MM/YYYY formatCAR_REGISTRATIONmust match VRM regex patternINVOICE_VALUEandVAT_TOTALmust be numeric in nnnnnn.nn formatORDER_NOmust be numeric- Field lengths must not exceed maximum limits
-
Validation Results:
- Valid rows are added to Cloud Task queue for invoice generation
- Invalid rows are logged with specific validation errors
- Processing statistics are generated (invoicesAddedToQueue, invoicesFailedValidation)
Cloud Task processing
The sequence diagram below illustrates how each record from the import file is processed through the queue.
Overview
Precondition checks
Before generating an invoice, the system performs the following validations:
-
Service Unit Lookup:
- Finds service unit within the provided account where supplierId matches DEPOT_NO
- Abort if: Service unit not found
-
Enquiry Lookup:
- Finds enquiry by matching
ORDER_NO(enquiryNumber) within the found service unit - Abort if: Enquiry not found
- Finds enquiry by matching
-
VRM Validation:
- Verifies
CAR_REGISTRATIONmatches the enquiry's VRM - Abort if: VRM mismatch
- Verifies
-
Enquiry Status Check:
- Verifies enquiry can be completed (not already in a terminal state)
- Abort if: Enquiry is in an invalid status
-
MOT Details Check:
- If enquiry has MOT job line, verifies MOT details are completed
- Abort if: MOT details missing
-
ADAS Certificate Check:
- If enquiry has ADAS calibration, verifies ADAS certificate is saved
- Abort if: ADAS certificate missing
-
Invoice Total Matching:
- Compares
INVOICE_VALUEwith ViSN's calculated grand total - Abort if: Totals do not match (logs both ViSN and IPP totals)
- Compares
Enquiry Progression
When Preconditions are satisfied
-
Progress to Completed:
- Updates enquiry status to "Completed"
- Adds event log entry with user "IPP"
-
Generate Invoice Data:
- Retrieves prefilled invoice data from the enquiry
- Merges IPP invoice details:
taxPointDate→ fromTAX_DATE(formatted as "dd MMM yyyy")invoiceNumber→ fromINVOICE_NOinvoiceSavedDate→ current timestampcalculatedGrandTotal→ from prefilled data
-
Save Invoice Data:
- Saves invoice data to:
accounts/{accountId}/serviceUnits/{serviceUnitId}/enquiries/{enquiryId}/invoices/invoice
- Saves invoice data to:
-
Create Invoice and Progress to Invoiced:
- Calls the Callable service endpoint
/api/v1/enquiry/invoices/createInvoice - The Callable service:
- Creates invoice record in the lease company's invoice collection
- Sets user as "IPP"
- Links to stock ID if available
- Progresses enquiry status from "Completed" to "Invoiced"
- Updates both service unit enquiry and lease company enquiry documents
- Sets
invoiceGeneratedflag totrue - Saves enquiry to billing system
- Updates search indices (Algolia/Typesense)
- Note: Invoice PDF generation and export record creation are automatically handled as part of the invoicing process
- Calls the Callable service endpoint
Logging and reporting
Error scenarios
| Scenario | Result | Logged Reason |
|---|---|---|
| Service unit not found | Aborted | supplierId: {depotNo} is not found in account |
| Enquiry not found | Aborted | enquiryNumber: {orderNo} is not found |
| VRM mismatch | Aborted | VRM: {carRegistration} does not match for enquiryId: {enquiryId} |
| Invalid enquiry status | Aborted | enquiryId: {enquiryId} is in {status} status |
| MOT details missing | Aborted | enquiryId: {enquiryId} MOT details are not completed |
| ADAS certificate missing | Aborted | enquiryId: {enquiryId} ADAS certificate is not completed |
| Invoice total mismatch | Aborted | enquiryId: {enquiryId} Invoice value does not match ViSN: {visnTotal} IPP: {ippTotal} |
| Schema validation failure | Skipped | Field-specific validation errors |
Error Handling
- Validation errors are logged per row with specific field errors
- Precondition failures are logged with specific reason (e.g., "VRM mismatch", "enquiry not found")
- Fatal errors trigger email notification to
fatalErrorEmailToAddress
Import Logs
- Location:
ancillary/logs/ippInvoicing/logs/{year}/{month}/{date}/logs - Each row processed logs:
- Row number
- VRM
- Enquiry number
- Validation status or error messages
- End-of-log entry contains aggregated statistics
Processing Statistics
invoicesAddedToQueue→ Number of valid invoices queuedinvoicesFailedValidation→ Number of rows that failed schema validationinvoicesGenerated→ Number of invoices successfully createdinvoicesFailedGeneration→ Number of invoices that failed during generation
Log CSV Export
- A scheduled function (
pubsub_generateIppInvoicingLogsCSV) generates CSV exports of the import logs - Trigger: Pub/Sub topic
generateIppInvoicingLogsCSV - Default: Exports today's logs (can be configured with specific date)
- Output Location:
exports/ippInvoicing/logs/{year}/{monthName}/{day}/{ipp_invoicing_logs_{year}-{month}-{day}.csv} - Content: All log entries from the import process, excluding the end-of-log-entry document
- Process Log: Creates a process log entry with type
KWIKFIT_IPP_INVOICEcontaining statistics
Admin UI Monitoring
- Process logs can be viewed in the Admin UI under Process Logs
- Process log type:
KWIKFIT_IPP_INVOICE - Displays statistics when import is successful:
- Number of invoices added to queue
- Number of invoices failed validation
- Number of invoices generated
- Number of invoices generation failed
Setup Required
Cloud Task Queue
The Cloud Task queue for IPP invoice generation should be configured:
- Queue Name: ipp-invoice-generation
- Target URL: Queue Services endpoint
/ipp-invoice-generation - Task Type: FOR_IPP_INVOICE_GENERATION
Generate Log CSV Export
A Cloud Scheduler should be created to generate daily CSV exports of IPP invoicing logs (note: the import file itself is JSON, but the log exports are CSV for reporting):
A Scheduler should be created in Cloud Scheduler with the following parameters:
- Name: Generate IPP invoicing logs CSV
- Region: europe-west2
- Frequency: Daily (recommended: 0 23 * * * - runs at 11 PM daily)
- TimeZone: GMT London
- Topic: projects/[PROJECT_ID]/topics/generateIppInvoicingLogsCSV
Message body: a JSON object including the following parameters (all optional):
- dateTimeStamp: in format yyyy-MMM-dd ex 2025-Jan-15, when skipped it will default to today's date
Note: The scheduler exports the today's logs by default. To export logs for a specific date, include the dateTimeStamp parameter in the message body.
Authored By: Rama on Dec 24, 2025